package com.pz.cloud.framework.model;

import org.jeecg.common.model.Callable;

import java.util.concurrent.CountDownLatch;

/**
 * 线程任务
 * 3hmzz
 * @param <E>
 */
public class ThreadTask<E> implements Runnable{
    private Callable callable;
    private E e;
    private CountDownLatch countDownLatch;

    public <T>ThreadTask(Callable<E,T> callable, E e, CountDownLatch countDownLatch){
        this.callable = callable;
        this.e = e;
        this.countDownLatch = countDownLatch;
    }
    public <T>ThreadTask(Callable<E,T> callable, E e){
        this.callable = callable;
        this.e = e;
    }

    @Override
    public void run() {
        try {
            callable.callback(e);
        }finally {
            if(countDownLatch!=null){
                countDownLatch.countDown();//线程计数器-1
            }
        }
    }
}
